package com.reviewcode.cachemicroservice.common.bean;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author vcorazon
 * @type Class
 * @description TODO
 * @since 2021/07/24 22:24
 */
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
@Slf4j
public class ExpirationExcutor implements Runnable{
    private final MicroCache<String, String> microCache;
    private final Integer periodCycle;

    @Override
    public void run() {
        while(true){
            try{
                microCache.removeExpiredItem();
                Thread.sleep(periodCycle);
            }catch (Exception e){
                log.info("定时清理异常信息：{}", e.getMessage());
            }
        }
    }
}
